import { DisplayUtil } from "../../../../common/DisplayUtil";
import { LayerManager } from "../../../manager/LayerManager";
import { Global } from "../../../../../com/gengine/global/Global";
import { EffectManager } from "../../../manager/EffectManager";
import { NavbarIconInfo } from "./NavbarIconInfo";
import { GuideArrow } from "../../guide/GuideArrow";
import { GuideArrowManager } from "../../../manager/GuideArrowManager";
import { TweenMax } from "../../../../../com/greensock/TweenMax";
import { Button } from "../../../../../fl/controls/Button";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { Lv70DramaItem } from "../../lv70fb/data/Lv70DramaItem";
import { 8 } from "../../../../../0/8";
type int = number;
//class NavbarButtonUIRow
    
    export  class NavbarButtonUIRow
    {
        

        /* internal  */resetContainers(): void
        {
            var loc1=null;
            if (this._flyContainer != null) 
            {
                DisplayUtil.removeAllChild(this._flyContainer);
            }
            else 
            {
                this._flyContainer = new Object /* flash.display.Sprite */();
                LayerManager.highestLayer.addChild(this._flyContainer);
            }
            if (this._preContainer != null) 
            {
                DisplayUtil.removeAllChild(this._preContainer);
            }
            else 
            {
                this._preContainer = new Object /* flash.display.Sprite */();
                LayerManager.highestLayer.addChild(this._preContainer);
            }
            this._cruOpBtn.x = this._startPoint.x - this.DistanceX * this._curTweeningInShowingIndex + 22;
            this._cruOpBtn.y = this._startPoint.y + 20;
            loc1 = this._cruOpBtn.localToGlobal(new Object /* flash.geom.Point */(0, 0));
            this._flyContainer.x = Global.stage.stageWidth / 2;
            this._flyContainer.y = Global.stage.stageHeight / 2;
            this._flyContainer.addChild(this._flyEffect);
            this._flyContainer.visible = true;
            this._preContainer.x = loc1.x;
            this._preContainer.y = loc1.y;
            this._preContainer.addChild(this._preShowEffect);
            this._preContainer.visible = false;
            return;
        }

        /* internal  */callbackHandler(): void
        {
            if (this._callback != null) 
            {
                this._callback.apply();
                this._callback = null;
            }
            return;
        }

        /* internal  */onFlyEffectCompleted(): void
        {
            DisplayUtil.removeMe(this._flyEffect);
            this._preContainer.visible = true;
            flash.utils.setTimeout(this.onShowIcon, 200);
            flash.utils.setTimeout(this.onPreShowEnd, this.ShowDelayTime + 100);
            return;
        }

        /* internal  */onPreShowEnd(): void
        {
            DisplayUtil.removeMe(this._preShowEffect);
            return;
        }

        /* internal  */onFlyAndShowComplete(): void
        {
            if (this._preShowEffect != null) 
            {
                DisplayUtil.removeMe(this._preShowEffect);
                this._preShowEffect.dispose(true);
                this._preShowEffect = null;
            }
            if (this._flyEffect != null) 
            {
                DisplayUtil.removeMe(this._flyEffect);
                this._flyEffect.dispose(true);
                this._flyEffect = null;
            }
            this.updateButtonsLayout();
            this.makeEffectTips();
            this._isTweening = false;
            if (this._callback != null) 
            {
                this._callback.apply();
                this._callback = null;
            }
            return;
        }

        /* internal  */onShowIcon(): void
        {
            this._cruOpBtn.x = this._startPoint.x - this.DistanceX * this._curTweeningInShowingIndex;
            this._cruOpBtn.y = this._startPoint.y;
            this._cruOpBtn.visible = true;
            return;
        }

        /* internal  */makeEffectTips(): void
        {
            var loc1=null;
            var loc2=null;
            if (this._curOpInfo == null) 
            {
                return;
            }
            if (this._curOpInfo.needGuidGrowEffect) 
            {
                this._cruOpBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClickToShowEffect);
                loc1 = new Object /* flash.filters.GlowFilter */(268435302, 1, 6, 6, 4);
                loc2 = [loc1];
                EffectManager.glowFilterReg(this._cruOpBtn, loc2, 0.9, 12, 3, 25);
            }
            if (this._curOpInfo.needGuidArrow) 
            {
                this.addArrowPointToButton(this._cruOpBtn);
            }
            return;
        }

        /* internal  */addArrowPointToButton(arg1: Object /* flash.display.DisplayObject */): void
        {
            this.setArrowsPosition(arg1);
            this._container.addChild(this.arrow);
            arg1.addEventListener(flash.events.MouseEvent.CLICK, this.clickToShowArrow);
            return;
        }

        /* internal  */setArrowsPosition(arg1: Object /* flash.display.DisplayObject */): void
        {
            if (arg1 == null) 
            {
                return;
            }
            this.arrow.x = arg1.x + 21;
            this.arrow.y = arg1.y - 8;
            return;
        }

        /* internal  */clickToShowArrow(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as Object /* flash.display.DisplayObject */;
            loc1.removeEventListener(flash.events.MouseEvent.CLICK, this.clickToShowArrow);
            DisplayUtil.removeMe(this.arrow);
            return;
        }

        /* internal  */onClickToShowEffect(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as Object /* flash.display.DisplayObject */;
            loc1.removeEventListener(flash.events.MouseEvent.CLICK, this.onClickToShowEffect);
            EffectManager.glowFilterUnReg(loc1);
            return;
        }

        /* internal  */updateButtonsLayout(): void
        {
            var loc3=false;
            var loc4=null;
            if (this._showStatusList == null) 
            {
                return;
            }
            var loc1=this._startPoint.x;
            var loc2=0;
            while (loc2 < this._showStatusList.length) 
            {
                loc3 = this._showStatusList[loc2] as Boolean;
                if ((loc4 = this._btns[loc2] as Object /* flash.display.DisplayObject */) != null) 
                {
                    if (loc3) 
                    {
                        loc4.visible = true;
                        loc4.x = loc1;
                        loc4.y = this._startPoint.y;
                        loc1 = loc1 - this.DistanceX;
                    }
                    else 
                    {
                        loc4.visible = false;
                    }
                }
                ++loc2;
            }
            if (!(this._lastArrowPointBtn == null) && !(this._arrow == null) && !(this._arrow.parent == null)) 
            {
                this.setArrowsPosition(this._lastArrowPointBtn);
            }
            return;
        }

        /* internal  */getIndexFromShowingList(arg1: int): int
        {
            var loc1=0;
            var loc2=0;
            while (loc2 < arg1) 
            {
                if (this._showStatusList[loc2]) 
                {
                    ++loc1;
                }
                ++loc2;
            }
            return loc1;
        }

        /* internal  */getCanOpIndex(arg1: NavbarIconInfo): int
        {
            if (this._isTweening) 
            {
                return -1;
            }
            if (arg1.iconName == null || arg1.iconName == "" || this._showStatusList == null || this._btns == null) 
            {
                return -1;
            }
            var loc1=this._btnNames.indexOf(arg1.iconName);
            if (loc1 < 0 || this._showStatusList[loc1]) 
            {
                return -1;
            }
            return loc1;
        }

        /* internal  */get arrow(): GuideArrow
        {
            if (this._arrow == null) 
            {
                this._arrow = new GuideArrow();
                this._arrow.updateDir(GuideArrowManager.Dir_B);
                this._arrow.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onArrowRemoved);
                this._arrow.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onArrowAdded);
            }
            return this._arrow;
        }

        /* internal  */onArrowRemoved(arg1: Object /* flash.events.Event */): void
        {
            this._lastArrowPointBtn = null;
            return;
        }

        /* internal  */onArrowAdded(arg1: Object /* flash.events.Event */): void
        {
            if (this._lastTiemrId != -1) 
            {
                flash.utils.clearTimeout(this._lastTiemrId);
            }
            this._lastTiemrId = flash.utils.setTimeout(this.onArrowTimerEnd, 15000);
            return;
        }

        /* internal  */flyAndShowbtnFlyEffect(): void
        {
            var targetPoint: Object /* flash.geom.Point */;
            var dx: int;
            var dy: int;
            var onFlyEffectComplete1: Function;

            var loc1;
            targetPoint = null;
            onFlyEffectComplete1 = null;
            onFlyEffectComplete1 = (): void
            {
                TweenMax.to(_flyContainer, ShowDelayTime / 1000, {"x": targetPoint.x, "y": targetPoint.y, "scaleX": 1, "scaleY": 1, "onComplete": onFlyEffectCompleted});
                tweenShowingIcons();
                return;
            }
            targetPoint = this._cruOpBtn.localToGlobal(new Object /* flash.geom.Point */(0, 0));
            this._flyContainer.scaleX = 0.2;
            this._flyContainer.scaleY = 0.2;
            dx = this._flyContainer.x + 7 * (targetPoint.x - this._flyContainer.x) / 8;
            dy = this._flyContainer.y + 3 * (targetPoint.y - this._flyContainer.y) / 4;
            TweenMax.to(this._flyContainer, 0.3, {"x": dx, "y": dy, "scaleX": 8, "scaleY": 8, "onComplete": onFlyEffectComplete1});
            return;
        }

        public get showStatusList(): Array<any>
        {
            if (this._showStatusList == null) 
            {
                return [];
            }
            return this._showStatusList.concat([]);
        }

        public init(arg1: Object /* flash.display.DisplayObjectContainer */, arg2: Array<any>): void
        {
            var loc2=null;
            var loc3=0;
            this._container = arg1;
            this._btnNames = arg2;
            this._btns = [];
            var loc1=0;
            while (loc1 < arg1.numChildren) 
            {
                loc2 = arg1.getChildAt(loc1);
                loc3 = this._btnNames.indexOf(loc2.name);
                if ((loc2 is flash.display.SimpleButton || loc2 is Button) && loc3 >= 0) 
                {
                    this._btns[loc3] = loc2;
                    if (loc3 == 0) 
                    {
                        this._startPoint = new Object /* flash.geom.Point */(loc2.x, loc2.y);
                    }
                }
                ++loc1;
            }
            return;
        }

        public initShow(arg1: Array<any>): void
        {
            if (arg1 == null || arg1.length == 0) 
            {
                return;
            }
            this._showStatusList = arg1;
            this.updateButtonsLayout();
            return;
        }

        public showGuideArrow(arg1: int): void
        {
            if (arg1 < 0 || arg1 >= this._btnNames.length) 
            {
                return;
            }
            if (this._showStatusList[arg1] == false) 
            {
                return;
            }
            var loc1=this._btns[arg1] as Object /* flash.display.DisplayObject */;
            if (loc1 == null) 
            {
                return;
            }
            this._lastArrowPointBtn = loc1;
            this.addArrowPointToButton(loc1);
            return;
        }

        public flyAndShowBtn(arg1: NavbarIconInfo, arg2: Function=null): void
        {
            var info: NavbarIconInfo;
            var callback: Function=null;
            var index: int;
            var _loadedTimes: int;
            var loadEffectCompleted: Function;

            var loc1;
            _loadedTimes = 0;
            loadEffectCompleted = null;
            info = arg1;
            callback = arg2;
            loadEffectCompleted = (arg1: SWFPlayer): void
            {
                var loc1;
                _loadedTimes++;
                if (_loadedTimes < 2) 
                {
                    return;
                }
                resetContainers();
                _isTweening = true;
                if (_curOpInfo.needFlyEffect) 
                {
                    flyAndShowbtnFlyEffect();
                }
                else 
                {
                    DisplayUtil.removeAllChild(_flyContainer);
                    flyAndShowbtnStartShow();
                }
                return;
            }
            index = this.getCanOpIndex(info);
            if (index < 0) 
            {
                if (callback != null) 
                {
                    callback.apply();
                }
                return;
            }
            this._curOpInfo = info;
            this._cruOpBtn = this._btns[index] as Object /* flash.display.DisplayObject */;
            this._showStatusList[index] = true;
            this._callback = callback;
            this._curTweeningIndex = index;
            this._curTweeningInShowingIndex = this.getIndexFromShowingList(index);
            this._flyEffect = ObjectPool.getObject(SWFPlayer);
            this._preShowEffect = ObjectPool.getObject(SWFPlayer);
            _loadedTimes = 0;
            this._flyEffect.loadComplete = loadEffectCompleted;
            this._flyEffect.load("UIByLevelFlyEffect.swf", ModelType.NormalSwf, null);
            this._preShowEffect.loadComplete = loadEffectCompleted;
            this._preShowEffect.load("UIByLevelPreShowEffect.swf", ModelType.NormalSwf, null);
            if (this._curOpInfo.preEndTime != 0) 
            {
                this.callbackHandler();
            }
            return;
        }

        /* internal  */onArrowTimerEnd(): void
        {
            this._lastTiemrId = -1;
            DisplayUtil.removeMe(this._arrow);
            return;
        }

        /* internal  */flyAndShowbtnStartShow(): void
        {
            flash.utils.setTimeout(this.onFlyEffectCompleted, this.ShowDelayTime);
            this.tweenShowingIcons();
            return;
        }

        /* internal  */tweenShowingIcons(): void
        {
            var loc5=null;
            var loc6=false;
            var loc1=false;
            var loc2=900;
            flash.utils.setTimeout(this.onFlyAndShowComplete, loc2);
            var loc3=false;
            var loc4=this._curTweeningIndex + 1;
            while (loc4 < this._showStatusList.length) 
            {
                loc5 = this._btns[loc4] as Object /* flash.display.DisplayObject */;
                if (loc6 = this._showStatusList[loc4] as Boolean) 
                {
                    loc5.visible = true;
                    loc3 = true;
                    TweenMax.to(loc5, loc2 / 1000 - 0.1, {"x": loc5.x - this.DistanceX});
                }
                ++loc4;
            }
            if (loc3 && !(this._arrow == null) && this._arrow.visible && !(this._arrow.parent == null)) 
            {
                TweenMax.to(this._arrow, loc2 / 1000 - 0.1, {"x": this._arrow.x - this.DistanceX});
            }
            return;
        }

        /* internal */ /* const */DistanceX: int=46;

        /* internal */ /* const */ShowDelayTime: int=400;

        /* internal */ /* var */_container: Object /* flash.display.DisplayObjectContainer */;

        /* internal */ /* var */_btns: Array<any>;

        /* internal */ /* var */_showStatusList: Array<any>;

        /* internal */ /* var */_btnNames: Array<any>;

        /* internal */ /* var */_isTweening: Boolean=false;

        /* internal */ /* var */_curTweeningIndex: int;

        /* internal */ /* var */_callback: Function;

        /* internal */ /* var */_flyEffect: SWFPlayer;

        /* internal */ /* var */_preShowEffect: SWFPlayer;

        /* internal */ /* var */_flyContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_preContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_cruOpBtn: Object /* flash.display.DisplayObject */;

        /* internal */ /* var */_curOpInfo: NavbarIconInfo;

        /* internal */ /* var */_curTweenItem: Lv70DramaItem;

        /* internal */ /* var */_startPoint: Object /* flash.geom.Point */;

        /* internal */ /* var */_curTweeningInShowingIndex: int;

        /* internal */ /* var */_lastTiemrId: int=-1;

        /* internal */ /* var */_arrow: GuideArrow;

        /* internal */ /* var */_lastArrowPointBtn: Object /* flash.display.DisplayObject */;
    }
